package com.spdzen.support;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class AdminLoginUtils {
	private static final String SESSION_ADMIN_LOGIN_INFO = "adminLoginInfo";

	public static Long getUserId() {
		Subject subject = SecurityUtils.getSubject();
		AdminLoginInfo info = (AdminLoginInfo) subject.getSession().getAttribute(SESSION_ADMIN_LOGIN_INFO);
		if (info == null) {
			return null;
		} else {
			return info.getUserId();
		}
	}

	public static AdminLoginInfo getLoginInfo() {
		Subject subject = SecurityUtils.getSubject();
		return (AdminLoginInfo) subject.getSession().getAttribute(SESSION_ADMIN_LOGIN_INFO);
	}

	public static void setLoginInfo(AdminLoginInfo info) {
		Subject subject = SecurityUtils.getSubject();
		subject.getSession().setAttribute(SESSION_ADMIN_LOGIN_INFO, info);
	}

	public static void removeLoginInfo() {
		Subject subject = SecurityUtils.getSubject();
		subject.getSession().removeAttribute(SESSION_ADMIN_LOGIN_INFO);
	}
}
